package controlLayer;
import modelLayer.*;


public class MachineCtr {
    
    private MachineContainer mcnCont;
    private Machine mcn;
    
    public MachineCtr() {
        mcnCont = MachineContainer.getInstance();
    }
    
    public void createMachine(String name, int barcode, double pricePerDay) {
        mcn = new Machine(name, barcode, pricePerDay);
        mcnCont.addMachine(mcn);
    }
    
    public Machine findMachine(int barcode) {
        mcn = mcnCont.findMachine(barcode);
        return mcn;
    }
    
    public void removeMachine(Machine mcn) {
        mcnCont.removeMachine(mcn);
    }
    
    public RentLine createRentLine(Machine mcn, int quantity) {
        RentLine rl = new RentLine(mcn, quantity);
        return rl;
    }
    
    public Item findItem(int serialNumber) {
        boolean found = false;
        int index = 0;
        while(index < mcn.items.size() && !found) {
            Item it = mcn.items.get(index);
            if(it.getSerialNumber() == serialNumber) {
                found = true;
            }
            else {
                index++;
            }
        }
        
        if(found) {
            return mcn.items.get(index);
        }
        else {
            return null;
        }
    }
    
    public void createItem(int serialNumber) {
        Item it = new Item(serialNumber);
        mcn.items.add(it);
        mcn.setItemsNo(mcn.getItemsNo()+1);
    }
    
    public void removeItem(Item it) {
        mcn.items.remove(it);
    }
}
